#include "AnaDef.h"

int main(int argc, char * argv[])
{
  for(int ii=0; ii<argc; ii++){
    printf("%d: %s\n", ii, argv[ii]);
  }
  if(argc!=2){
    printf("argc!=2\n");return 1;
  }

  ifstream fin(argv[1]);
  TString buff;

  const Int_t bits[]={0,1,2,3,4,5,10,11,12,13, 14,20,21,22};
  const Int_t nbit = sizeof(bits)/sizeof(Int_t);
  Double_t counts[nbit];
  for(Int_t ib=0; ib<nbit; ib++){
    counts[ib]=0;
  }

  while(fin.good()){
    fin>>buff;
    if(buff!=""){
      TFile *ff = new TFile(buff);
      if(!ff){
        printf("%s no file!!\n", buff.Data()); continue;
      }

      TList *ll = (TList*)ff->Get("xlu_list");
      if(!ll){
        printf("%s no list!\n", buff.Data()); gDirectory->ls(); 
        ff->Close();
        delete ff;
        continue;
      }

      TH1I * cuts = (TH1I*) ll->FindObject("cuts");
      if(!cuts){
        printf("%s no cuts!\n", buff.Data()); exit(1);
      }

      for(Int_t ib=0; ib<nbit; ib++){
        counts[ib]+=cuts->GetBinContent(1+bits[ib]);
      }
      ff->Close();
      delete ff;
    }
  }
  for(Int_t ib=0; ib<nbit; ib++){
    printf("bit %d: %.0f\n", bits[ib], counts[ib]);
  }

  return 0;
}
